package com.ecocent.common;

import java.util.HashSet;
import java.util.Set;

import com.ecocent.common.bean.Bean;
import com.ecocent.common.util.JsonUtil;
import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

public class Test {
	
	@JsonFilter("userFilter")
	public  interface UserFilterMixIn{

    }
	public static void main(String[] args) throws Exception {
		ObjectMapper mapper = new ObjectMapper(); 
		 Set<String> fields = new HashSet<String>();
		 fields.add("c");
        FilterProvider filters = new SimpleFilterProvider().addFilter("userFilter", 
                SimpleBeanPropertyFilter.serializeAllExcept(new String[]{"a"})); 
        mapper.setFilterProvider(filters);
        mapper.addMixIn(Bean.class,UserFilterMixIn.class);
        Bean value = new Bean();
		value.setA("a");
		value.setB("b");
		System.out.println(mapper.writeValueAsString(value));
		//mapper.setSerializerProvider(p).getSerializerProviderInstance()....addMixIn(Bean.class, null);
//		((SimpleFilterProvider)mapper.getSerializationConfig().getFilterProvider()).removeFilter("userFilter");
//		 Bean a = new Bean();
//			a.setA("aaaa");
//			a.setB("baa");
//		FilterProvider filters1 = new SimpleFilterProvider().addFilter("userFilter", 
//                SimpleBeanPropertyFilter.filterOutAllExcept(new String[]{"b"})); 
//        mapper.setFilterProvider(filters1);
        //mapper.addMixIn(Bean.class,null);

		System.out.println(mapper.writeValueAsString(value));

//		long t = System.currentTimeMillis();
//		for(int i=0;i<1000000;i++){
//			filters = new SimpleFilterProvider().addFilter("userFilter", 
//	                SimpleBeanPropertyFilter.filterOutAllExcept(new String[]{"c"})); 
//	        mapper.setFilterProvider(filters);
//	        
//			Bean value = new Bean();
//			value.setA("a");
//			value.setB("b");
//			//System.out.println(mapper.writeValueAsString(value));
//			mapper.writeValueAsString(value);
//		}
//		System.out.println(System.currentTimeMillis()-t);
//		t = System.currentTimeMillis();
//		for(int i=0;i<1000000;i++){
//			Bean value = new Bean();
//			value.setA("a");
//			value.setB("b");
//			JsonUtil.getJsonStringFromObject(value);
//		}
//		System.out.println(System.currentTimeMillis()-t);

	}

}
